package com.atguigu.tingshu.album.mapper;

import com.atguigu.tingshu.model.album.AlbumInfo;
import com.atguigu.tingshu.query.album.AlbumInfoQuery;
import com.atguigu.tingshu.vo.album.AlbumInfoVo;
import com.atguigu.tingshu.vo.album.AlbumListVo;
import com.atguigu.tingshu.vo.album.AlbumStatVo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;


@Mapper
public interface AlbumInfoMapper extends BaseMapper<AlbumInfo> {

    /*
    * 分页查询专辑列表
    * */
    IPage<AlbumListVo> getAlbumList(Page<AlbumListVo>albumListVoPage,@Param("vo") AlbumInfoQuery albumInfoQuery);

    void updateAlbumInfo(Long albumId, AlbumInfoVo albumInfoVo);

    /*
    * 根据专辑id获取统计信息
    * */
    @Select("select\n" +
            "    stat.album_id,\n" +
            "    MAX(IF(stat.stat_type = '0701', stat.stat_num, 0))   as playStatNum,\n" +
            "    MAX(IF(stat.stat_type = '0702', stat.stat_num, 0))   as collectStatNum,\n" +
            "    MAX(IF(stat.stat_type = '0703', stat.stat_num, 0))   as praiseStatNum,\n" +
            "    MAX(IF(stat.stat_type = '0704', stat.stat_num, 0))   as commentStatNum\n" +
            "from album_stat stat\n" +
            "where stat.album_id = #{albumId}\n" +
            "group by stat.album_id")
    AlbumStatVo getAlbumStatVo(@Param("albumId") Long albumId);
}
